/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Views;

import Classes.Materiel;
import Classes.Secteur;
import Classes.Type;
import DAO.DBConnect;
import DAO.MaterielDAO;
import java.sql.SQLException;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author guig
 */
public class vueAutre extends javax.swing.JFrame {

    private Map<Integer, Classes.Type>listeType;
    private Map<Integer, Secteur>listeSecteur;
    private Map<Long, Materiel>listeMateriel;
    private Materiel materielGlobal;
    DefaultTableModel dtm;
    
    private vueGlobale mainFrame;
    
    /**
     * Creates new form vueAutre
     */
    public vueAutre(JFrame mainFrame, Map<Integer, Classes.Type>listeType, Map<Integer, Secteur>listeSecteur, Map<Long, Materiel>listeMateriel) {
        initComponents();
        this.listeType = listeType;
        this.listeSecteur = listeSecteur;
        this.listeMateriel = listeMateriel;
        
        this.mainFrame = (vueGlobale) mainFrame;
        materielGlobal = new Materiel();
    }



    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        ComboType = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        ComboSecteur = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        ED_NumCompta = new javax.swing.JTextField();
        ED_NumSerie = new javax.swing.JTextField();
        ED_Nom = new javax.swing.JTextField();
        ED_Date = new javax.swing.JTextField();
        ED_Prix = new javax.swing.JTextField();
        ED_Garantie = new javax.swing.JTextField();
        ED_Amortissement = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        ED_descriptif = new javax.swing.JTextField();
        BTN_Add = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setText("Matériels :");

        ComboType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ComboTypeActionPerformed(evt);
            }
        });

        jLabel2.setText("Type :");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "n° Code barre", "Nom", "Descriptif", "Prix "
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel3.setText("Année :");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2010", "2011", "2012", "2013", "2014" }));

        jLabel4.setText("Secteur :");

        jLabel5.setText("N° Compta :");

        jLabel6.setText("N° Série : ");

        jLabel7.setText("Nom :");

        jLabel8.setText("Descriptif :");

        jLabel9.setText("Date d'achat :");

        jLabel10.setText("Prix HT :");

        jLabel11.setText("Garantie : ");

        jLabel12.setText("N° BC : ");

        jLabel14.setText("Amortissement : ");

        ED_NumCompta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ED_NumComptaActionPerformed(evt);
            }
        });

        BTN_Add.setText("Ajouter");
        BTN_Add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTN_AddActionPerformed(evt);
            }
        });

        jButton1.setText("Retour");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Supprimer");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton5.setText("Annuler");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(255, 255, 255)
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(ED_Date, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
                                            .addComponent(ED_NumCompta)
                                            .addComponent(ED_Amortissement)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(24, 24, 24)
                                        .addComponent(ComboType, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(12, 12, 12)))
                                .addGap(37, 37, 37)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel12))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextField8)
                                    .addComponent(ED_Prix)
                                    .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(ED_NumSerie))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGap(55, 55, 55)
                                        .addComponent(jLabel8)
                                        .addGap(18, 18, 18)
                                        .addComponent(ED_descriptif, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(68, 68, 68)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel7)
                                                    .addComponent(jLabel4)))
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                .addGap(46, 46, 46)
                                                .addComponent(jLabel11)))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(ED_Nom)
                                            .addComponent(ComboSecteur, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jButton2)
                                                    .addComponent(ED_Garantie, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(0, 0, Short.MAX_VALUE))))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(BTN_Add, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButton1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(ComboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(ComboSecteur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(ED_NumCompta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ED_NumSerie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(ED_Nom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(ED_Date, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ED_Prix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel11)
                        .addComponent(ED_Garantie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel14)
                        .addComponent(ED_Amortissement, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel12)
                        .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel8))
                    .addComponent(ED_descriptif, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(BTN_Add)
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton1)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ComboTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ComboTypeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ComboTypeActionPerformed

    /**
     * Action s'éxécutant à l'ouverture de la fenêtre
     * @param evt 
     */
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        for(Map.Entry<Integer, Classes.Type> t : listeType.entrySet()){ 
            ComboType.addItem(t.getValue());
         }
        for(Map.Entry<Integer, Secteur> s : listeSecteur.entrySet()){
             ComboSecteur.addItem(s.getValue());
         }
        
        dtm = (DefaultTableModel)jTable1.getModel(); 
        remplirJTable(); 
    }//GEN-LAST:event_formWindowOpened

    private void ED_NumComptaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ED_NumComptaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ED_NumComptaActionPerformed

    /**
     * Traitement de l'ajout et de la modification d'un matériel
     * @param evt 
     */
    private void BTN_AddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTN_AddActionPerformed

        if (BTN_Add.getText() == "Ajouter"){

        try {
             
            Materiel myMateriel = new Materiel();
            MaterielDAO myMaterielDAO = new MaterielDAO(DBConnect.getInstance());

            myMateriel.setDescriptif(ED_descriptif.getText());
            myMateriel.setNumCompta(Integer.decode(ED_NumCompta.getText()));
            myMateriel.setNumSerie(ED_NumSerie.getText());
            myMateriel.setNom(ED_Nom.getText());
            myMateriel.setDateHT(ED_Date.getText());
            myMateriel.setPrixHT(Double.parseDouble(ED_Prix.getText()));
            myMateriel.setGarantie(Integer.decode(ED_Garantie.getText()));
            myMateriel.setAmortissement(Double.parseDouble(ED_Amortissement.getText()));
            myMateriel.setIdT(((Classes.Type) ComboType.getSelectedItem()).getIdT());
            myMateriel.setIdSc(((Secteur) ComboSecteur.getSelectedItem()).getIdSc());

                myMaterielDAO.insert(myMateriel);
                long CB = 0000000000000;
            listeMateriel.put(CB, myMateriel);
                JOptionPane.showMessageDialog(this, "Votre matériel " + ED_Nom.getText() +" a été ajouté avec succès !", "Information", JOptionPane.INFORMATION_MESSAGE);

        
         } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Une erreur est survenue durant l'enregistrement du matériel => " + e.toString(), "HOUSTON we've had problem !!!", JOptionPane.ERROR_MESSAGE);
        }
        }
        else {
            materielGlobal = (Materiel)   jTable1.getValueAt(jTable1.getSelectedRow(), 0);
            MaterielDAO myMaterielDAO = new MaterielDAO(DBConnect.getInstance());
             try {
            materielGlobal.setDescriptif(ED_descriptif.getText());
            materielGlobal.setNumCompta(Integer.decode(ED_NumCompta.getText()));
            materielGlobal.setNumSerie(ED_NumSerie.getText());
            materielGlobal.setNom(ED_Nom.getText());
            materielGlobal.setDateHT(ED_Date.getText());
            materielGlobal.setPrixHT(Double.parseDouble(ED_Prix.getText()));
            materielGlobal.setGarantie(Integer.decode(ED_Garantie.getText()));
            materielGlobal.setIdT(((Classes.Type) ComboType.getSelectedItem()).getIdT());
            materielGlobal.setIdSc(((Secteur) ComboSecteur.getSelectedItem()).getIdSc());

            myMaterielDAO.update(materielGlobal);
            dtm = (DefaultTableModel)jTable1.getModel(); 

             remplirJTable();
             
             JOptionPane.showMessageDialog(this, "Votre matériel " + ED_Nom.getText() +" a été modifié avec succès !", "Information", JOptionPane.INFORMATION_MESSAGE);
             

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Une erreur est survenue durant l'enregistrement du matériel => " + e.toString(), "HOUSTON we've had problem !!!", JOptionPane.ERROR_MESSAGE);
        }
        }
      
    }//GEN-LAST:event_BTN_AddActionPerformed

    /**
     * Bouton retour qui ferme la fenêtre en cours
     * @param evt 
     */
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * Action qui récupère la fenêtre principale suite à la fermeture de la fenêtre d'importation
     * @param evt 
     */
    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        this.mainFrame.setVisible(true);
    }//GEN-LAST:event_formWindowClosed

    /**
     * Action de suppression d'un matériel
     * @param evt 
     */
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        if (jTable1.getSelectedRowCount()!=0) {
            MaterielDAO myMaterielDAO = new MaterielDAO(DBConnect.getInstance());
            try{ 

                int reply = JOptionPane.showConfirmDialog(null, "Voulez-vous supprimer ce matériel ?", "Confirmation avant suppression", JOptionPane.YES_NO_OPTION);
                if (reply == JOptionPane.YES_OPTION) {
                    materielGlobal = (Materiel)   jTable1.getValueAt(jTable1.getSelectedRow(), 0);

                    myMaterielDAO.delete(materielGlobal); 

                    listeMateriel.remove(materielGlobal.getNumCB());


                    dtm = (DefaultTableModel)jTable1.getModel(); 
                    remplirJTable();
                    JOptionPane.showMessageDialog(this, "Suppression terminée !", "Information", JOptionPane.INFORMATION_MESSAGE);
                }

            }catch(Exception e){
                JOptionPane.showMessageDialog(this, "Veuillez choisir un matériel dans la liste !", "Une erreur est survenue", JOptionPane.ERROR_MESSAGE);
            }
        }else{
            JOptionPane.showMessageDialog(this, "Veuillez séléctionner un matériel dans la liste !", "Une erreur est survenue !!!", JOptionPane.ERROR_MESSAGE);
        }    
       
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * Récupération des informations suite au clic sur le tableau
     * @param evt 
     */
    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // TODO add your handling code here:
        try{
        
            materielGlobal = (Materiel)   jTable1.getValueAt(jTable1.getSelectedRow(), 0);
            ED_NumCompta.setText(Integer.toString(materielGlobal.getNumCompta()));
            ED_Date.setText(materielGlobal.getDateHT());
            ED_NumSerie.setText(materielGlobal.getNumSerie());
            ED_Prix.setText(Double.toString(materielGlobal.getPrixHT()));
            ED_Nom.setText(materielGlobal.getNom());
            ED_Garantie.setText(Integer.toString(materielGlobal.getGarantie()));
            ED_descriptif.setText(materielGlobal.getDescriptif());

            if (materielGlobal.getNumCB() != 0){
                BTN_Add.setText("Enregistrer"); 
           }
            
        }catch (Exception e){
                JOptionPane.showMessageDialog(this, "Veuillez choisir un matériel dans la liste !", "Une erreur est survenue", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jTable1MouseClicked

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        ED_descriptif.setText("");
        ED_NumCompta.setText("");
        ED_NumSerie.setText("");
        ED_Nom.setText("");
        ED_Date.setText("");
        ED_Prix.setText("");
        ED_Garantie.setText("");
        
        BTN_Add.setText("Ajouter"); 
        
    }//GEN-LAST:event_jButton5ActionPerformed
    
    /**
     * Fonction qui recharge la Table
     */
     private void remplirJTable(){
         while( dtm.getRowCount()!=0){
            dtm.removeRow(0);
            }
       for(Map.Entry<Long, Materiel> m : listeMateriel.entrySet()){
           Vector v = new Vector();
           v.add(m.getValue());
           v.add(m.getValue().getNom());
           v.add(m.getValue().getDescriptif());
           v.add(m.getValue().getPrixHT());
           dtm.addRow(v);
        } 
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BTN_Add;
    private javax.swing.JComboBox ComboSecteur;
    private javax.swing.JComboBox ComboType;
    private javax.swing.JTextField ED_Amortissement;
    private javax.swing.JTextField ED_Date;
    private javax.swing.JTextField ED_Garantie;
    private javax.swing.JTextField ED_Nom;
    private javax.swing.JTextField ED_NumCompta;
    private javax.swing.JTextField ED_NumSerie;
    private javax.swing.JTextField ED_Prix;
    private javax.swing.JTextField ED_descriptif;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField8;
    // End of variables declaration//GEN-END:variables
}
